<?php
declare (strict_types = 1);

namespace app\common\validate;

use app\common\config\Client;

class Role extends ValidateBase
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'id' => ['require'],
        'uuid' => ['require'],
        'creator' => ['require'],
        'updater' => ['require'],
        'name' => ['require'],
        'client' => ['require','checkEnumValid'=>Client::class],
        'roles' => ['array'],
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'id.require' => 'id不能为空',
        'uuid.require' => 'uuid不能为空',
        'creator.require' => '创建者信息不能为空',
        'updater.require' => '更新者信息不能为空',
        'name.require' => '角色名称不能为空',
        'client.require' => '客户端类型未知',
        'client.checkEnumValid' => '非法客户端类型',
        'roles.array' => '角色信息格式错误'
    ];

    /**
     * 验证场景
     * 格式：'场景'=>['需要验证的字段']
     */
    protected $scene = [
        'add'  =>  ['uuid','creator','updater','roles','client','name'],
        'del'  =>  ['id','uuid'],
        'query'  =>  ['id','uuid'],
        'edit'  =>  ['id','uuid','roles','name']
    ];
}
